package it.myAndroid.ShadowSMS;

import it.myAndroid.ShadowSMS.R;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.IBinder;
import android.util.Log;
import android.preference.PreferenceManager;
 


/**
 * @author stefazzi
 * @date 19/feb/2013
 * @version 
 */
@SuppressWarnings("unused")
public class ShadowSMSServices extends Service
{
	private final BroadcastReceiver smsReceiver = new ShadowSMSSmsReceiver();
	
	@Override
	public IBinder onBind(Intent intent) 
	{
		return null;
	}
	
	@Override
	public void onDestroy()
	{
		//deregistro la ricezione degli SMS 
		unregisterReceiver(smsReceiver);
		Log.i(ShadowSMSServices.class.getName(),"Deregistrazione ricezione SMS - Chiusura ShadowSMS");
	}
	
	@Override
	public void onStart(Intent intent, int startid) 
	{
		//Registro la ricezione dei messaggi
  	IntentFilter filter = new IntentFilter("android.provider.Telephony.SMS_RECEIVED"); 
  	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) 
  	{

  		filter .setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY - 1);
  	} 
  	else 
  	{
  		filter .setPriority(Integer.MAX_VALUE);
  	}
  	filter.setPriority( IntentFilter.SYSTEM_HIGH_PRIORITY );
  	registerReceiver( smsReceiver, filter );
  	
  	Log.i(ShadowSMSServices.class.getName(),"Registrazione ricezione SMS - Apertura ShadowSMS");
  	
		intent.setAction(Intent.ACTION_MAIN); 
		intent.addCategory(Intent.CATEGORY_LAUNCHER); 
		intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
		ComponentName cn = new ComponentName(this, ShadowSMSActivity.class); 
		intent.setComponent(cn); 
		Log.d(ShadowSMSServices.class.getName(),"Avvio servizio");
		startActivity(intent); 
	}
	
}
